package com.example.test.proxy_two;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

public class Invaction implements InvocationHandler {

    private BaseService baseService;
    public Invaction(BaseService baseService) {
        this.baseService = baseService;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        Object value;
        String me = method.getName();
        if(me.equals("eat")){
            wash();
            value = method.invoke(baseService,args);
        }else {
            value = method.invoke(baseService,args);
            wash();
        }
        return value;
    }

    public void wash(){
        System.out.println("-----------洗手----------");
    }
}
